//
// Created by Aivin on 2018/8/8.
//

#ifndef WKPLAYER_WKFFMPEG_H
#define WKPLAYER_WKFFMPEG_H

extern "C"
{
//c++ 兼容 c语言写的库
#include <libavformat/avformat.h>

#include <libavutil/time.h>
};

#include <pthread.h>
#include "PlayerStatus.h"
#include "WkJavaCall.h"
#include "WkAudio.h"
#include <pthread.h>
#include "WkFFmpeg.h"
#include "../utils/WkLoger.h"
#include "../config/WkConfig.h"




class WkFFmpeg {
public:
    WkJavaCall * wkJavaCall ;
    PlayerStatus* playerStatus ;
    const char* source ;
    pthread_t  ffmpegThread ;
    pthread_mutex_t init_mutex ;
    bool exit = false ;
    // 要初始化 ，否则会有野指针
    WkAudio * wkAudio =NULL ;
    AVFormatContext* avFormatContext ;
    int duration = 0;
    pthread_mutex_t seek_mutex;
    bool isCircle = false ;

public :
    WkFFmpeg(WkJavaCall* wkJavaCall1 ,PlayerStatus* playerStatus , const char* source);
    ~WkFFmpeg();
    void preparePlayer();
    void decodecFFmpegThread();
    void start();
    void pause();
    void resume();
    void release();
    void seek(int64_t secds);
    void setVolume(int percent);
    void setMute(int mute);
    void setPitch(float pitch);
    void setSpeed(float speed);
    int getSampleRate();
    void startStopRecord(bool start);
    void setCircle(bool isCircle);

};

#endif //WKPLAYER_WKFFMPEG_H
